package com.htudata.core.handler;

import com.htudata.common.vo.ResponseResult;
import com.htudata.core.exception.ServiceException;
import com.htudata.core.util.ResultGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {


  @ExceptionHandler({ServiceException.class})
  @ResponseBody
  @ResponseStatus(HttpStatus.OK)
  private ResponseResult handleException(ServiceException e) {
    log.error("", (Throwable)e);
    return ResultGenerator.genErrorResult(e.getCode(), e.getStatus(), e.getMessage());
  }
  
  @ExceptionHandler({Exception.class})
  @ResponseBody
  @ResponseStatus(HttpStatus.OK)
  private ResponseResult handleException(Exception e) {
    log.error("", e);
    return ResultGenerator.genErrorResult("system error");
  }
}
